package com.maweirdos.ai.core.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * Author:  Maweirdos
 * Date:  2025/7/8 23:53
 * Description:  向量数据库配置
 */
@Configuration
public class MVectorStoreConfig {

    @Resource
    private MDocumentLoader documentLoader;

    /**
     * 创建基于内存的向量数据库
     * @param embeddingModel
     * @return
     */
    @Bean
    public VectorStore inMemoryVectorStore(EmbeddingModel embeddingModel) {
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(embeddingModel).build();
        List<Document> documents = documentLoader.loadMarkdown();
        simpleVectorStore.doAdd(documents);
        return simpleVectorStore;
    }
}
